import { inject, observer } from "mobx-react";
import React from 'react';
import { Button, Card, Row, Col, Modal, message } from 'antd';
import { WeaNewScroll, WeaRichText, WeaBrowser, WeaTextarea, WeaLocaleProvider, WeaDialog } from 'ecCom';
import { toJS } from "mobx";
import '../style/taskDynamic.less';
import { imgZoom} from '../../../util/index';
const confirm = Modal.confirm;
const getLabel = WeaLocaleProvider.getLabel;
import Edit from "../../portal/edit";
import { JlChild, jlParamsHandle, Daily, Log } from "../../tools/dtConfig";
@inject("taskDynamicStore")
@observer
export class TaskDynamic extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            selectedKey: "0",
            value: "3",
            viewAttr: 3,
            selectedDynamicTab: 0,
            showDailyDiv: false,
            showExDiv: false,
            showReply: {},
            showDailyEdit: {},
            visible: false,
            showRich: false,
            richValue: '',
            richValueChangeMethod: () =>{},
            richMethod: () =>{},
            isCreate:true
        };
    }

    componentDidMount(){
        let dom = ReactDOM.findDOMNode(this);
		imgZoom(dom, ".wea-cl-content");
        const { taskid, taskDynamicStore } = this.props;
        taskDynamicStore.setTaskId(taskid);
        taskDynamicStore.initData();
    }

    componentDidUpdate(prevProps, prevState) {
		let dom = ReactDOM.findDOMNode(this);
		imgZoom(dom, ".wea-cl-content");
    }
    
    componentWillReceiveProps(nextProps){
        if(this.props.taskid !== nextProps.taskid){
            const { taskid, taskDynamicStore } = nextProps;
            this.setState({ selectedDynamicTab: 0, showDailyDiv: false, showExDiv: false, showReply: {}, showRich: false });
            taskDynamicStore.setTaskId(taskid);
            taskDynamicStore.initData();
        }
    }

    render() {
        const { selectedDynamicTab, showRich, visible, richValue } = this.state;
        const checkOptions = [
            {
                title: getLabel('332','全部'),
                index: 0
            }, {
                title: getLabel('20620','日报'),
                index: 1
            }, {
                title: getLabel('518347','交流'),
                index: 2
            }, {
                title: getLabel('83','日志'),
                index: 3
            }
        ];
        const { submitDaily, exchangeList, loading, canSubmitDaily } = this.props.taskDynamicStore;
        // const {exchangeList,logList,_BrowserList,taskid,dailys,setReply,saveReply,alldatas} = this.props.taskDynamicStore;
        const height = document.body.offsetHeight - 260.3;
        let scrollHeight = ($(".e9theme-layout-header").length > 0 || $(".e8theme-layout-header").length > 0) ? height - 55 : height;
        if(this.props.fromPortal){
            scrollHeight = scrollHeight - 51;
        }
        const richSubmitfun = selectedDynamicTab == 1 ? submitDaily : this.dosubmit;
        const richid = {
            "1": "create_daily",
            "2": "create_discuss"
        }[selectedDynamicTab.toString()]
        let richPlaceholder = {
            "1": getLabel('518257','填写日报'),
            "2": getLabel('518258','填写相关交流')
        }[selectedDynamicTab.toString()];
        const canSubmit = {
            "1": canSubmitDaily,
            "2": true
        }[selectedDynamicTab.toString()];
        if(!canSubmit){
            richPlaceholder += '('+getLabel('520676','一天只能提交一次') +')';
        }
        const richProps = {
            transfStr: this.transfStr,
            richChange: this.richChange,
            richSubmitfun: richSubmitfun,
            showRichfun: this.showRichfun,
            showDialogfun: this.showDialogfun,
            setIsCreate: (bool) =>{this.setState({isCreate:bool})},
            exchangeList,
            richid,
            showRich,
            richPlaceholder,
            loading,
            canSubmit
        }

        const richDom = (hasEdit = true) => (<Row ecId={`${this && this.props && this.props.ecId || ''}_Row@2bnbh8`}>
            <div className='dongtai-wraps' style={{ backgroundColor: '#ffffff', marginBottom: '10px', padding: "5px 20px" }}>
                {hasEdit && <Edit ecId={`${this && this.props && this.props.ecId || ''}_Edit@g660fz`} {...richProps} />}
                {this.getDynamicContent()}
            </div>
        </Row>);
        const Elem = (
            <div className='prj-dynamic-tab'>
                <div>
                    {checkOptions.map((opt, index) => {
                        if(index==selectedDynamicTab){
                            return (<div className='prj-dynamic-tab-item' onClick={() =>{this.changeDynamicTab(index);this.setState({richValue:''});}}><span key={index} className="active">{opt.title}</span></div>)
                        }else{
                            return (<div className='prj-dynamic-tab-item' onClick={() =>{this.changeDynamicTab(index);this.setState({richValue:''});}}><span key={index}>{opt.title}</span></div>)
                        }
                    })}
                </div>
            </div>
        );

        const editHeight = window.screen.width>=1920?"600px":"400px";

        return (
            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@o6pqw4`} style={{ paddingLeft: "0px", paddingRight: "0px", height: "100%" }} className='task_card_new_r'>
                <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@dp9h65`} style={{ fontSize: "14px" }}>
                    <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@f2yaeo`} span="20">
                        <div className='task_card_new-dt-title'>
                            <span className='task_card_new-main-card-title'>{getLabel('518353','任务动态')}</span>&nbsp;
                        </div>
                    </Col>
                    <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@ibu71a`} span="4">
                        <span style={{float:"right",color:"#a5a5a5"}}>
                        </span>
                    </Col>
                </Row>
                <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@aoubvm`}>
                <div>
                    {Elem}
                </div>
                </Row>
                <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@k1jtuv`} height={this.props.isDialog?"calc( 100% - 74px )":scrollHeight} style={{padding: '0px'}}>
                    {
                        {
                            '0': richDom(false),
                            '1': richDom(),
                            "2": richDom(),
                            '3': richDom(false)
                        }[selectedDynamicTab.toString()]
                    }
                </WeaNewScroll>
                <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@p5sld7`}
                    title={getLabel(433,"描述")}
                    icon='icon-coms-project'
                    iconBgcolor='#217346'
                    visible={visible}
                    buttons={[
                        <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@stt743@submit`} type="primary" onClick={() => { this.getRichSubmitfun('create'); this.showDialogfun(false) }}>{getLabel(383336, "提交")}</Button>,
                        <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@mfj7a4@cancel}`} type="ghost" onClick={() => this.setState({ visible: false })}>{getLabel(201,"取消")}</Button>
                    ]}
                    onCancel={() => this.setState({ visible: false })}
                    style={{ width: 'calc(100% - 200px)', height: editHeight }}
                >
                    <Edit ecId={`${this && this.props && this.props.ecId || ''}_Edit@v33xtj`} transfStr={this.transfStr} richChange={this.richChange} richid={richid} value={richValue} visibleDialog={true} exchangeList={exchangeList} loading={loading} />,
                </WeaDialog>
            </Row>
        )
    }
    richChange = (text) => {
        const { taskDynamicStore: { setDaily } } = this.props;
        const { selectedDynamicTab, isCreate, richValueChangeMethod } = this.state;
        if(isCreate){
            this.setState({richValue:text});
            if(selectedDynamicTab == 1){
                setDaily(text);
            }else if(selectedDynamicTab == 2){
                this.onChange('create', text);
            }
        }else{
            richValueChangeMethod(text);
        }
    }
    showRichfun = (bool) => {
        this.setState({ showRich: bool })
    }
    showDialogfun = (visible) => {
        this.setState({ visible })
    }
    huifuHandle = (item) => {
        let { showReply } = this.state;
        let showReply1 = showReply;
        showReply1[item.id] = !showReply1[item.id];
        this.setState({ showReply: showReply1 });
    }
    shanchuHandle = () => {
    }
    bianjiHandle = (item,tabKey) => {
        let { showDailyEdit } = this.state;
        let showDailyEdit1 = showDailyEdit;
        showDailyEdit1[item.id] = !showDailyEdit1[item.id];
        this.setState({ richValue: item.content });
        this.setState({ showDailyEdit: showDailyEdit1 });
        this.setState({richMethod:(v) =>{this.editDaily(item.id,tabKey);}});
        this.setState({richValueChangeMethod:(text) =>{this.setState({richValue:text});}});
        this.setState({isCreate:false});
    }
    tijiaoHandle = (showReply, item, submitType) => {
        const { saveReply } = this.props.taskDynamicStore;
        saveReply(item.id, submitType);
        let showReply1 = showReply;
        showReply1[item.id] = !showReply1[item.id];
        this.setState({ showReply: showReply1 });
    }
    getDynamicContent = () => {
        let datas = [];
        let { selectedDynamicTab, showReply, showDailyEdit } = this.state;
        const { exchangeList, logList, _BrowserList, taskid, dailys, setReply, saveReply, alldatas } = this.props.taskDynamicStore;
        let _exchangeList = toJS(exchangeList);
        if (selectedDynamicTab == 0) {
            alldatas.datas && alldatas.datas.map((item, index) => {
                const { type } = item;
                if (type == 1) {
                    datas.push(
                        <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@te49d8@${index}`} style={{ borderBottom: '1px solid #E2E2E2', marginTop: '20px' }}>
                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@b750lq@${index}`} span="3">
                                <img src={item.creater.imgurl} className="manager-img" style={{ marginLeft: "0px" }} />
                            </Col>
                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@2b3pdt@${index}`} span="21">
                                {
                                    showDailyEdit[item.id]?
                                    <div>
                                        <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@305zgv@${index}`} className='exchange-row'>
                                            <a href={'javaScript:openhrm(' + item.creater.id + ');'} onClick={e => window.pointerXY(e)} >
                                                <span className='exchange-hrm'>{item.creater.name}:&nbsp;&nbsp;</span>
                                            </a>
                                        </Row>
                                        <Edit ecId={`${this && this.props && this.props.ecId || ''}_Edit@rihsa3@${index}`}
                                            richid={`${item.id}_daily`}
                                            showRichfun={this.showRichfun}
                                            showDialogfun={this.showDialogfun}
                                            value={item.content}
                                            transfStr={this.transfStr}
                                            showRich={true}
                                            richChange={(text) =>{this.setState({richValue:text});}}
                                            richSubmitfun={(v) =>{this.editDaily(item.id,0);}}
                                            showRichfun={(bool) =>{
                                                let showDailyEdit1 = showDailyEdit;
                                                showDailyEdit1[item.id] = bool;
                                                this.setState({ showDailyEdit: showDailyEdit1 });
                                            }}
                                            exchangeList={_exchangeList}
                                            loading={false}
                                        />
                                    </div>:
                                    <div>
                                        <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@wg40bd@${index}`} className='exchange-row'>
                                            <a href={'javaScript:openhrm(' + item.creater.id + ');'} onClick={e => window.pointerXY(e)} >
                                                <span className='exchange-hrm'>{item.creater.name}:&nbsp;&nbsp;</span>
                                            </a>
                                            <span dangerouslySetInnerHTML={{ __html: item.content }}></span>
                                        </Row>
                                        <span className='exchange-date'>{item.createdate + ' ' + item.createtime}</span>
                                        <span style={{ float: 'right' }}>
                                            {item.canEdit&&<span className='exchange-operate' onClick={() => {
                                                this.deleteDaily(item.id,0);
                                            }}><a>{getLabel(131966,"删除")}</a>
                                            </span>}
                                            {item.canEdit&&<span className='exchange-operate' onClick={() => this.bianjiHandle(item,0)}><a>{getLabel(126036, "编辑")}</a>
                                            </span>}
                                            <span className='exchange-operate' onClick={() => this.huifuHandle(item)}><a>{getLabel('128123', '回复')}</a>
                                            </span>
                                        </span>
                                    </div>
                                }
                                {
                                    item.replys&&item.replys.map((item,index) =>{
                                        return <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@j3ptky@${index}`} style={{padding:0}}>
                                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@qq8wyu@${index}`} style={{padding:0}}>
                                                <span className='exchange-hrm'>
                                                    <a href={'javaScript:openhrm('+item.creater.id+');'} onClick={e => window.pointerXY(e)} >
                                                        <span className='exchange-hrm'>{item.creater.name}&nbsp;&nbsp;</span>
                                                    </a>
                                                </span>
                                                <span className='exchange-date'>{item.createdate+' '+item.createtime}</span>
                                            </Row>
                                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@k5a6w0@${index}`} style={{ padding: 0 }}>
                                                <span dangerouslySetInnerHTML={{ __html: getLabel('128123','回复')+'：' + item.content }}></span>
                                            </Row>
                                        </Row>
                                    })
                                }
                                {showReply[item.id]&&<Row ecId={`${this && this.props && this.props.ecId || ''}_Row@o5t3n6@${index}`} style={{padding:0}}>
                                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@vcva1w@${index}`} style={{padding:0}}>
                                    <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@i27bd5@${index}`} viewAttr={2} onChange={(v) =>{setReply(v)}} />
                                    </Row>
                                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@jsvlg9@${index}`} style={{padding:'5px 0'}}>
                                    <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@35xl5d@${index}`} key="submit" type="primary" size="small" style={{ display: 'inline-block', borderRadius: '3px', float: 'right' }} onClick={() => {
                                        saveReply(item.id,"alltask");
                                        let showReply1 = showReply;
                                        showReply1[item.id]=!showReply1[item.id];
                                        this.setState({showReply:showReply1});
                                    }} >{getLabel(383336,"提交")}</Button>
                                    </Row>
                                </Row>}
                            </Col>
                        </Row>
                    )
                } else if (type == 2) {
                    let _exchangeList = toJS(exchangeList);
                    let BrowserList = toJS(_BrowserList);
                    const sortid = taskid;
                    let wf_auth_url = _exchangeList ? _exchangeList.wf_auth_url : "";
                    let doc_auth_url = _exchangeList ? _exchangeList.doc_auth_url : "";
                    let acc_auth_url = _exchangeList ? _exchangeList.acc_auth_url : "";
                    
                    let browserParam = {
                        hasAddBtn: false,
                        hasAdvanceSerach: true,
                        idSeparator: ",",
                        isAutoComplete: 1,
                        isDetail: 0,
                        isMultCheckbox: false,
                        isSingle: true,
                        linkUrl: "/hrm/resource/HrmResource.jsp?id=",
                        pageSize: 10,
                        quickSearchName: "",
                        title: getLabel(383424,"人力资源"),
                        type: "1",
                        viewAttr: 1,
                    }
                    Array.isArray(BrowserList.datas) && BrowserList.datas.map((element, index) => {
                        if (element.id == item.id) {
                            let replaceDatas = [];
                            replaceDatas.push(element.creater);
                            element['id'] == BrowserList[element['id']]

                            let showDom = element.isEdit == true ?
                                <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@2uoalr@${index}`}>
                                    <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@vbjseb@${index}`} height='252px'>
                                        <div style={{ backgroundColor: '#ffffff', height: '242px', marginBottom: '10px' }}>
                                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@nfa2oh@${index}`}>
                                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@il3kzh`} span={3}>
                                                    <img className="manager-img" src={`${element.creater.imgurl}`} style={{ borderRadius: '20px' }} />
                                                </Col>
                                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@n6f6xu`} span={21}>
                                                    <div className="jiaoliu-box">
                                                        <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@9rr73c`} {...browserParam} replaceDatas={replaceDatas} style={{ display: 'inline-block' }} />
                                                    </div>
                                                </Col>
                                            </Row>
                                            <Edit ecId={`${this && this.props && this.props.ecId || ''}_Edit@m676k1@${index}`}
                                                richid={`${element.id}_discuss`}
                                                showRichfun={this.showRichfun}
                                                showDialogfun={this.showDialogfun}
                                                value={BrowserList[element.id].remark}
                                                transfStr={this.transfStr}
                                                showRich={true}
                                                richChange={(text) =>{this.onChange(element.id, text);this.setState({richValue:text});}}
                                                richSubmitfun={(v) =>{this.dosubmit(element.id)}}
                                                showRichfun={(bool) =>{this.docancel(index,bool)}}
                                                exchangeList={_exchangeList}
                                                loading={false}
                                            />
                                        </div>
                                    </WeaNewScroll>
                                </Row>
                                : <div style={{ borderBottom: '1px solid #E2E2E2', backgroundColor: '#ffffff', marginTop: '20px' }}>
                                    <JlChild ecId={`${this && this.props && this.props.ecId || ''}_JlChild@3jh8hm@${index}`} element={element} replaceDatas={replaceDatas} sortid={sortid} wf_auth_url={wf_auth_url} doc_auth_url={doc_auth_url} acc_auth_url={acc_auth_url} />
                                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@6b3eb6@${index}`} className='dynamic-exchange-operate'>
                                        <span className='dynamic-exchange-time'>
                                            {element.time}
                                        </span>
                                        {
                                            element.canedit ? (
                                                <div className='dynamic-exchange-operate'>
                                                    <span
                                                        className="wea-mbwcbr-item icon-coms-edit"
                                                        style={{ cursor: 'pointer', color: '#b2b2b2', paddingRight: '5px' }}
                                                        onClick={() => {
                                                            this.setState({richValue:BrowserList[element.id].remark});
                                                            this.edit(element.id);
                                                            this.setState({richMethod:(v) =>{this.dosubmit(element.id)}});
                                                            this.setState({richValueChangeMethod:(text) =>{this.onChange(element.id, text);this.setState({richValue:text})}});
                                                            this.setState({isCreate:false});
                                                        }}
                                                    ><span style={{ fontSize: "12px", color: '#666666' }}>&nbsp;{`${getLabel(126036, "编辑")}`}</span></span>
                                                    <span
                                                        className="wea-mbwcbr-item icon-coms-delete"
                                                        onClick={() => this.delete(element.id)}
                                                        style={{ right: '10px', cursor: 'pointer', color: '#b2b2b2' }}
                                                    ><span style={{ fontSize: "12px", color: '#666666' }}>&nbsp;{`${getLabel(131966, "删除")}`}</span></span>
                                                </div>
                                            ) : ""
                                        }
                                    </Row>
                                </div>
                            datas.push(showDom);
                        }
                    })
                } else if (type == 3) {
                    datas.push(<Log ecId={`${this && this.props && this.props.ecId || ''}_Log@6emczj@${index}`} {...item} />)
                }
            })
        } else if (selectedDynamicTab == 1) {
            dailys && dailys.map((item, index) => {
                datas.push(
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@kswpvq@${index}`} style={{ borderBottom: '1px solid #E2E2E2', marginTop: '20px' }}>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@8bmrru@${index}`} span="3">
                            <img src={item.creater.imgurl} className="manager-img" style={{ marginLeft: "0px" }} />
                        </Col>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@js6g16@${index}`} span="21">
                            {
                                showDailyEdit[item.id]?
                                <div>
                                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@9jnqxz@${index}`} className='exchange-row'>
                                        <a href={'javaScript:openhrm(' + item.creater.id + ');'} onClick={e => window.pointerXY(e)} >
                                            <span className='exchange-hrm'>{item.creater.name}:&nbsp;&nbsp;</span>
                                        </a>
                                    </Row>
                                    <Edit ecId={`${this && this.props && this.props.ecId || ''}_Edit@y6w02n@${index}`}
                                        richid={`${item.id}_daily`}
                                        showRichfun={this.showRichfun}
                                        showDialogfun={this.showDialogfun}
                                        value={item.content}
                                        transfStr={this.transfStr}
                                        showRich={true}
                                        richChange={(text) =>{this.setState({richValue:text});}}
                                        richSubmitfun={(v) =>{this.editDaily(item.id,1);}}
                                        showRichfun={(bool) =>{
                                            let showDailyEdit1 = showDailyEdit;
                                            showDailyEdit1[item.id] = bool;
                                            this.setState({ showDailyEdit: showDailyEdit1 });
                                        }}
                                        exchangeList={_exchangeList}
                                        loading={false}
                                    />
                                </div>:
                                <div>
                                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@srp4a6@${index}`} className='exchange-row'>
                                        <a href={'javaScript:openhrm(' + item.creater.id + ');'} onClick={e => window.pointerXY(e)} >
                                            <span className='exchange-hrm'>{item.creater.name}:&nbsp;&nbsp;</span>
                                        </a>
                                        <span dangerouslySetInnerHTML={{ __html: item.content }}></span>
                                    </Row>
                                    <span className='exchange-date'>{item.createdate + ' ' + item.createtime}</span>
                                    <span style={{ float: 'right' }}>
                                        {item.canEdit&&<span className='exchange-operate' onClick={() => {
                                            this.deleteDaily(item.id,1);
                                        }}><a>{getLabel(131966,"删除")}</a>
                                        </span>}
                                        {item.canEdit&&<span className='exchange-operate' onClick={() => this.bianjiHandle(item,1)}><a>{getLabel(126036, "编辑")}</a>
                                        </span>}
                                        <span className='exchange-operate' onClick={() => this.huifuHandle(item)}><a>{getLabel('128123', '回复')}</a>
                                        </span>
                                    </span>
                                </div>
                            }
                            {
                                item.replys&&item.replys.map((item,index) =>{
                                    return <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@2dmqfc@${index}`} style={{padding:0}}>
                                        <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@rtojpf@${index}`} style={{padding:0}}>
                                            <span className='exchange-hrm'>
                                                <a href={'javaScript:openhrm('+item.creater.id+');'} onClick={e => window.pointerXY(e)} >
                                                    <span className='exchange-hrm'>{item.creater.name}&nbsp;&nbsp;</span>
                                                </a>
                                            </span>
                                            <span className='exchange-date'>{item.createdate+' '+item.createtime}</span>
                                        </Row>
                                        <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@lefa9y@${index}`} style={{ padding: 0 }}>
                                            <span dangerouslySetInnerHTML={{ __html: getLabel('128123','回复')+'：' + item.content }}></span>
                                        </Row>
                                    </Row>
                                })
                            }
                            {showReply[item.id]&&<Row ecId={`${this && this.props && this.props.ecId || ''}_Row@k5i7j7@${index}`} style={{padding:0}}>
                                <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@0vhatr@${index}`} style={{padding:0}}>
                                <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@fb8ekf@${index}`} viewAttr={2} onChange={(v) =>{setReply(v)}} />
                                </Row>
                                <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@gb1aip@${index}`} style={{padding:'5px 0'}}>
                                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@cuxcu2@${index}`} key="submit" type="primary" size="small" style={{ display: 'inline-block', borderRadius: '3px', float: 'right' }} onClick={() => {
                                    saveReply(item.id,"daily");
                                    let showReply1 = showReply;
                                    showReply1[item.id]=!showReply1[item.id];
                                    this.setState({showReply:showReply1});
                                }} >{getLabel(383336,"提交")}</Button>
                                </Row>
                            </Row>}
                        </Col>
                    </Row>
                )
            })
        } else if (selectedDynamicTab == 2) {
            let _exchangeList = toJS(exchangeList);
            let BrowserList = toJS(_BrowserList);
            const sortid = taskid;
            let exchangeListDatas = _exchangeList ? _exchangeList.datas : [];
            let wf_auth_url = _exchangeList ? _exchangeList.wf_auth_url : "";
            let doc_auth_url = _exchangeList ? _exchangeList.doc_auth_url : "";
            let acc_auth_url = _exchangeList ? _exchangeList.acc_auth_url : "";

            let browserParam = {
                hasAddBtn: false,
                hasAdvanceSerach: true,
                idSeparator: ",",
                isAutoComplete: 1,
                isDetail: 0,
                isMultCheckbox: false,
                isSingle: true,
                linkUrl: "/hrm/resource/HrmResource.jsp?id=",
                pageSize: 10,
                quickSearchName: "",
                title: getLabel(383424,"人力资源"),
                type: "1",
                viewAttr: 1,
            }
            Array.isArray(BrowserList.datas) && BrowserList.datas.map((element, index) => {
                if (index != 0) {
                    let replaceDatas = [];
                    replaceDatas.push(element.creater);
                    element['id'] == BrowserList[element['id']]

                    let showDom = element.isEdit == true ?
                        <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@jj3xa2@${index}`}>
                            <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@1516zy@${index}`} height='252px'>
                                <div style={{ backgroundColor: '#ffffff', height: '242px', marginBottom: '10px' }}>
                                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@z8ndb8@${index}`}>
                                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@51fm61`} span={3}>
                                            <img className="manager-img" src={`${element.creater.imgurl}`} style={{ borderRadius: '20px' }} />
                                        </Col>
                                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@gspkcz`} span={21}>
                                            <div className="jiaoliu-box">
                                                <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@imv5d1`} {...browserParam} replaceDatas={replaceDatas} style={{ display: 'inline-block' }} />
                                            </div>
                                        </Col>
                                    </Row>
                                    <Edit ecId={`${this && this.props && this.props.ecId || ''}_Edit@3nj08w@${index}`}
                                        richid={`${element.id}_discuss`}
                                        showRichfun={this.showRichfun}
                                        showDialogfun={this.showDialogfun}
                                        value={BrowserList[element.id].remark}
                                        transfStr={this.transfStr}
                                        showRich={true}
                                        richChange={(text) =>{this.onChange(element.id, text);this.setState({richValue:text});}}
                                        richSubmitfun={(v) =>{this.dosubmit(element.id)}}
                                        showRichfun={(bool) =>{this.docancel(index,bool)}}
                                        exchangeList={_exchangeList}
                                        loading={false}
                                    />
                                </div>
                            </WeaNewScroll>
                        </Row>
                        : <div style={{ borderBottom: '1px solid #E2E2E2', backgroundColor: '#ffffff', marginTop: '20px' }}>
                            <JlChild ecId={`${this && this.props && this.props.ecId || ''}_JlChild@1teigf@${index}`} element={element} replaceDatas={replaceDatas} sortid={sortid} wf_auth_url={wf_auth_url} doc_auth_url={doc_auth_url} acc_auth_url={acc_auth_url} />
                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@1f2nlz@${index}`} className='dynamic-exchange-operate'>
                                <span className='dynamic-exchange-time'>
                                    {element.time}
                                </span>
                                {
                                    element.canedit ? (
                                        <div className='dynamic-exchange-operate'>
                                            <span
                                                className="wea-mbwcbr-item icon-coms-edit"
                                                style={{ cursor: 'pointer', color: '#b2b2b2', paddingRight: '5px' }}
                                                onClick={() => {
                                                    this.setState({richValue:BrowserList[element.id].remark});
                                                    this.edit(element.id);
                                                    this.setState({richMethod:(v) =>{this.dosubmit(element.id)}});
                                                    this.setState({richValueChangeMethod:(text) =>{this.onChange(element.id, text);this.setState({richValue:text})}});
                                                    this.setState({isCreate:false});
                                                }}
                                            ><span style={{ fontSize: "12px", color: '#666666' }}>&nbsp;{`${getLabel(126036, "编辑")}`}</span></span>
                                            <span
                                                className="wea-mbwcbr-item icon-coms-delete"
                                                onClick={() => this.delete(element.id)}
                                                style={{ right: '10px', cursor: 'pointer', color: '#b2b2b2' }}
                                            ><span style={{ fontSize: "12px", color: '#666666' }}>&nbsp;{`${getLabel(131966, "删除")}`}</span></span>
                                        </div>
                                    ) : ""
                                }
                            </Row>
                        </div>
                    datas.push(showDom);
                }
            })
            exchangeListDatas && exchangeListDatas.length == 1 && datas.push(<div style={{ textAlign: 'center', height: '85px' }}>
                <span className="icon-blog-Unhappy" style={{ display: 'inline-block', marginTop: '30px' }}><span style={{ paddingLeft: '5px' }}>{getLabel(383567, "暂无相关交流")}</span></span>
            </div>)
        } else if (selectedDynamicTab == 3) {
            logList && logList.map((item, index) => {
                datas.push(<Log ecId={`${this && this.props && this.props.ecId || ''}_Log@mbohtg@${index}`} {...item} />);
            })
        }
        if(datas.length  == 0){
            datas.push(   <p style={{ textAlign: 'center', color: '#999', marginTop: 10 }} >
            <i className='icon-coms-Invalid' /> {getLabel('83553',"暂无数据")}
 </p>);
        }
        return datas;
    }

    dosubmit = (id) => {
        const {exchangeSave,_BrowserList,setBrowserList,taskid} = this.props.taskDynamicStore;
		let BrowserList = toJS(_BrowserList);
		let oldBrowserList = { ...BrowserList }
		const sortid = taskid;
		let params = oldBrowserList[id];
		let mewParams = { ...params }
		let canSubmit = false;
		for (let key in mewParams) {
			if (key != 'id' && key != 'sortid') {
				if (key == 'remark') {
					if (mewParams[key]) {
						canSubmit = true
					}
				}
			}
		}

		if (params.docids.length == 0) {
			delete mewParams.docids
		}
		if (params.projectids.length == 0) {
			delete mewParams.projectids
		}
		if (params.relatedcus.length == 0) {
			delete mewParams.relatedcus
		}
		if (params.relateddoc.length == 0) {
			delete mewParams.relateddoc
		}
		if (params.relatedprj.length == 0) {
			delete mewParams.relatedprj
		}
		if (params.relatedwf.length == 0) {
			delete mewParams.relatedwf
		}
		if (params.docids.length > 0) {
			let docidsarr = []
			params.docids.forEach((_e, _index) => {
				docidsarr.push(_e['id']);
			})
			mewParams.docids = docidsarr.join(',');
		}
		if (params.projectids.length > 0) {
			let projectidssarr = []
			params.projectids.forEach((_e, _index) => {
				projectidssarr.push(_e['id']);
			})
			mewParams.projectids = projectidssarr.join(',');

		}
		if (params.relatedcus.length > 0) {//客户和任务有问题
			let relatedcusarr = []
			params.relatedcus.forEach((_e, _index) => {
				relatedcusarr.push(_e['id']);
			})
			mewParams.relatedcus = relatedcusarr.join(',');

		}
		if (params.relateddoc.length > 0) {
			let relateddocarr = []
			params.relateddoc.forEach((_e, _index) => {
				relateddocarr.push(_e['id']);
			})
			mewParams.relateddoc = relateddocarr.join(',');

		}
		if (params.relatedprj.length > 0) {
			let relatedprjarr = []
			params.relatedprj.forEach((_e, _index) => {
				relatedprjarr.push(_e['id']);
			})
			mewParams.relatedprj = relatedprjarr.join(',');

		}
		if (params.relatedwf.length > 0) {
			let relatedwfarr = []
			params.relatedwf.forEach((_e, _index) => {
				relatedwfarr.push(_e['id']);
			})
			mewParams.relatedwf = relatedwfarr.join(',');

		}
		mewParams['id'] = id == 'create' ? '' : id;
		mewParams['sortid'] = sortid;
		let stateBrowserList = { ...BrowserList };
		stateBrowserList['create']['docids'] = []
		stateBrowserList['create']['projectids'] = []
		stateBrowserList['create']['relatedcus'] = []
		stateBrowserList['create']['relateddoc'] = []
		stateBrowserList['create']['relatedprj'] = []
		stateBrowserList['create']['relatedwf'] = []
		stateBrowserList['create']['remark'] = ''

		if (canSubmit) {
			setBrowserList(stateBrowserList);
            exchangeSave(mewParams);
            this.setState({showExDiv:false});
		} else {
			message.error(getLabel(126982,"请填写内容"));
		}
	}

	docancel = (e,flag=false) => {
		const {exchangeList,changeDiscussList} = this.props.taskDynamicStore;
		let _exchangeList = toJS(exchangeList);
		let oldexchangeList = { ..._exchangeList }
		oldexchangeList.datas.forEach((element, index) => {
			if (e == index) {
				element.isEdit = flag;
			}
		})
		changeDiscussList(oldexchangeList)
	}

    transfStr = (name = '', ids = '', list = [], type = '', id = '') => {
		const {_BrowserList,setBrowserList,exchangeList,taskid} = this.props.taskDynamicStore;
		let BrowserList = toJS(_BrowserList);
		let _exchangeList = toJS(exchangeList);
		let acc_auth_url = _exchangeList ? _exchangeList.acc_auth_url : "";
		let sortid = taskid;
		let str = '';
		let idsArr = [];
		const mirror = {
			37: "doc",
			prjtsk: "task",
			18: "crm",
			152: "workflow",
			135: "project",
			workplan: "workplan",
			blogTemplate: "blogTemplate"
		}
		const browserType = {
			37: "docids",
			prjtsk: "relatedprj",
			18: "relatedcus",
			152: "relatedwf",
			135: "projectids",//项目
			Upload: "relateddoc",//附件
		}
		list.map(item => {
			if (name === 'Browser') {
				let urlstr=this.openProjectAppLink(mirror[type],item.id,sortid);
				str +=`&nbsp;<a  href='${urlstr}' target='new'  linkid='${item.id}' linkType='${mirror[type]}'  unselectable='off' contenteditable='false' style='cursor:pointer;text-decoration:underline !important;margin-right:8px'>${item.name || item.showname}</a>&nbsp;`
				idsArr.push(item.id)
			}
			if (name === 'Upload' && type === 'image') {
				str += '&nbsp;<img class="formImgPlay" src="' + item.imgSrc + '" onclick="ecCom.WeaRichText.playImg(this)" data-imgsrc="' + item.imgSrc + '" />&nbsp;'
			}
			if (name === 'Upload' && type === 'file') {
				str += `&nbsp;<a onclick='openProjectDiscussDoc(this,${ids[0]},${sortid},${acc_auth_url})' unselectable='off' contenteditable='false' style='cursor:pointer;text-decoration:underline !important;margin-right:8px'>${item.filename}</a>&nbsp;`
				if (item.showLoad) {
					let urlstr=item.loadlink+"&sortid="+sortid;
					str += `<a href='${urlstr}' target='_blank'  unselectable='off' contenteditable='false' style='cursor:pointer;text-decoration:underline !important;margin-right:8px'>${getLabel(258,"下载")}(${item.filesize})</a>&nbsp;`
				}
			}
		})

		let oldBrowserList = { ...BrowserList };
		if (oldBrowserList[id] == undefined) {
			oldBrowserList[id] = {};
		}
		if (name != 'Upload') {
			oldBrowserList[id][browserType[type]] = list;
		} else {
			oldBrowserList[id]['relateddoc'].push({ id: ids[0] })

		}
		setBrowserList(oldBrowserList);
		return str
	}

    onChange = (id, text) => {
		const {_BrowserList,setBrowserList} = this.props.taskDynamicStore;
		let BrowserList = toJS(_BrowserList);
		let oldBrowserList = { ...BrowserList };
		if (oldBrowserList[id] == undefined) {
			oldBrowserList[id] = {};
		}
		oldBrowserList[id]['remark'] = text;
		setBrowserList(oldBrowserList);
    }
    
    edit = (_id) => {
		const {exchangeList,changeDiscussList,_BrowserList,setBrowserList} = this.props.taskDynamicStore;
		let _exchangeList = toJS(exchangeList);
		let BrowserList = toJS(_BrowserList);
		let oldBrowserList = { ...BrowserList };
		let oldexchangeList = { ..._exchangeList }
		oldexchangeList.datas.forEach((element, index) => {
			if (_id == element['id']) {
				element.isEdit = true;
				if (oldBrowserList[_id] == undefined) {
					oldBrowserList[_id] = {};
				}
				oldBrowserList[_id].relatedwf = element.relatedwf;
				oldBrowserList[_id].docids = element.docids;
				oldBrowserList[_id].projectids = element.projectids;
				oldBrowserList[_id].relatedcus = element.relatedcus;
				oldBrowserList[_id].relateddoc = element.relateddoc;
				oldBrowserList[_id].relatedprj = element.relatedprj;
			}
		})
		setBrowserList(oldBrowserList);
		changeDiscussList(oldexchangeList)
    }
    
    delete = (e) => {
		const {exchangeDelete} = this.props.taskDynamicStore;
		confirm({
			title : getLabel(131329,"信息确认"),
			content : getLabel(15097,"确定要删除吗？"),
			onOk(){
				exchangeDelete({id:e});
			},
			onCancel() {}
	        })
    }

    deleteDaily = (e,type) => {
		const {deleteDaily,prjid} = this.props.taskDynamicStore;
		confirm({
			title : getLabel(131329,"信息确认"),
			content : getLabel(15097,"确定要删除吗？"),
			onOk(){
				deleteDaily({ id: e, prjid: prjid },type);
			},
			onCancel() {}
	        })
    }

    changeDynamicTab = (index) =>{
        const {getPortalProjectDynamicInfo,getDailys,getExchangeList,setExchangeList,setBrowserList} = this.props.taskDynamicStore;
        if(index==0){
            getPortalProjectDynamicInfo("alltask");
        }else if(index==1){
            getDailys();
        }else if(index==2){
            setExchangeList({});
            setBrowserList({});
            getExchangeList();
        }else if(index==3){
            getPortalProjectDynamicInfo("tasklog");
        }
        this.setState({ selectedDynamicTab: index, showDailyDiv: false, showExDiv: false, showReply: {}, showRich: false });
    }

    openProjectAppLink=(linkType, linkid, prjid)=>{
		const {exchangeList} = this.props.taskDynamicStore;
		let _exchangeList = toJS(exchangeList);
		let wf_auth_url = _exchangeList ? _exchangeList.wf_auth_url : "";
		let doc_auth_url = _exchangeList ? _exchangeList.doc_auth_url : "";
		let acc_auth_url = _exchangeList ? _exchangeList.acc_auth_url : "";
        if (linkType == "doc")
            return `/spa/document/index.jsp?id=${linkid}&prjid=${prjid}`+doc_auth_url;
        else if (linkType == "task")
            return `/spa/prj/index.html#/main/prj/taskCard?taskid=${linkid}`;
        else if (linkType == "crm")
            return `/spa/crm/static/index.html#/main/crm/customerView?customerId=${linkid}`;
        else if (linkType == "workflow")
            return `/spa/workflow/static4form/index.html#/main/workflow/req?fromModul=prj&modulResourceId=${prjid}&requestid=${linkid}`+wf_auth_url;
        else if (linkType == "project")
            return `/spa/prj/index.html#/main/prj/projectCard?prjid=${prjid}`;
        else
            return '';
    }
    
    getRichSubmitfun = (v) =>{
        const { taskDynamicStore: { submitDaily } } = this.props;
        const { selectedDynamicTab, isCreate, richMethod } = this.state;
        if(isCreate){
            if(selectedDynamicTab == 1){
                submitDaily(v);
            }else if(selectedDynamicTab == 2){
                this.dosubmit(v);
            }
        }else{
            richMethod();
        }
    }

    editDaily = (id,tabKey) =>{
        const { taskDynamicStore: { editDaily } } = this.props;
        const { richValue } = this.state;
        editDaily(id,richValue,tabKey);
    }

}
